<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button>点击</button>
    <script>
        /*
        1.在ES6中没有变量提升，所以必须先定义类，才能通过类实例化对象
        2.类里面的共有属性和方法一定要加this使用
        */
        var that;
        class Star{
            constructor(uname,age){
                that = this;
                this.uname = uname;
                this.age = age;
                this.btn = document.querySelector("button");
                this.btn.onclick = this.sing;
            }

            sing(){
                console.log(that.uname);//这里的that里面存储的是constructor里面的this
            }
        }
        var ldh = new Star("刘德华");
    </script>
</body>
</html>